﻿
@{
    ViewBag.Title = "DataExportView";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}
@section head{
    <script src="~/Scripts/exportJs.js"></script>
}

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>数据统计</legend>
</fieldset>
<form class="layui-form" enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">搜索</label>
        <div class="layui-input-block">
            <input type="text" id="SearchText" name="Title1" required lay-verify="required" onkeypress="getKey()" placeholder="输入设备名" class="layui-input" style="width:300px;float:left;">
            <input type="text" value="" style="display:none" />
            <button type="button" class="layui-btn layui-btn-normal" style="float:left;" onclick="SearchFunc()"><i class="layui-icon">&#xe615;</i></button>


            @*<button type="button" class="layui-btn layui-btn-normal" onclick="apply()"><i class="layui-icon">&#xe63b;</i></button>*@
        </div>
    </div>
</form>
<table id="demo" lay-filter="UserTableList"></table>

<div id="DateTimeLayer" style="display:none;">
    <form class="layui-form" style="margin-top:10px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="TimeStart">
                </div>
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="TimeEnd">
                </div>
                <button type="button" class="layui-btn layui-btn-danger" style="float:left;" id="BtnExport"><i class="layui-icon">&#xe61f;</i>保存</button>
            </div>
        </div>
    </form>
    <table id="demo2" lay-filter="DeviceTableList"></table>
</div>
<div style="font-size:12px;margin-top:10px;margin-bottom:10px;margin-left:15px;width:100%;position: absolute;left: 0px;bottom: 0px;">
    ©2020 德器(重庆)科技有限公司|DEQI(CQ) TECHNOLOGY.CO.,LTD 服务热线 400-9019-505
    @*重庆环元环境科学研究院*@
</div>

<script type="text/javascript">

    var table;
    var now = new Date();
    now.setHours(now.getHours() - 1);
    layui.use(['form', 'table', 'upload', 'layer','laydate'], function () {
        table = layui.table;
        var laydate = layui.laydate;
        var tab = parent.tab;
        var form = layui.form;
        var layer = layui.layer;
        var IsValidate = 0;
        var index;
        var MN;

        //执行一个laydate实例
        laydate.render({
            elem: '#TimeStart' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#TimeEnd' //指定元素
        });


        //第一个实例
        table.render({
            elem: '#demo'
            , method: 'post'
            //, height: 315
            , url: '/Panel/DataExportTableRequest' //数据接口
            , page: true //开启分页
            , where: { SortName: "a.MN", Order: "Desc", Condition: " and 1=1" }
            , limits: [10, 50, 100]

            , cols: [[ //表头
                { field: 'Name', title: '设备名称', width: 200, fixed: 'left' }
                , { field: 'Address', title: '设备地址', width: 200 }
                , {
                    field: 'state', title: '状态', width: 60,
                    templet: function (d) {
                        var LastTime = new Date(Date.parse(d.LastTime));
                        if (LastTime > now) {
                            return "<span style='color:green'>在线</span>";
                        }
                        else {
                            return "<span style='color:red'>离线</span>";
                        }

                    }
                }

                , {
                    field: 'Y1', title: '油烟1', width: 150,
                    templet: function (d) {
                        return d.Y1 + "|" + d.Y2 + " (mg/m³)";

                    }
                }
                , {
                    field: 'V1', title: '非甲烷总烃1', width: 150,
                    templet: function (d) {
                        return d.V1 + "|" + d.V2 + " (mg/m³)";

                    }
                }
                , {
                    field: 'K1', title: '颗粒物1', width: 150,
                    templet: function (d) {
                        return d.K1 + "|" + d.K2 + " (mg/m³)";

                    }
                }
                , {
                    field: 'amp1', title: '风机', width: 100,
                    templet: function (d) {
                        return d.amp1  + " (A)";

                    }
                }
                , {
                    field: 'amp2', title: '净化器', width: 100,
                    templet: function (d) {
                        return d.amp2 + " (A)";

                    }
                }
                , {
                    field: "operation", title: "操作", width: 150,
                    templet: function (d) {
                        return '' +
                            '<a class="layui-btn layui-btn-xs" lay-event="Export">导出</a>';
                    }
                }
            ]]
        });

        table.on("tool(UserTableList)", function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent == 'Export') {

                //var formstr = "PreEstId::" + data.PreEstId + "&Name::" + data.Name + "&ProjectName::" + ProjectName;
                //$.down('/Estimate/EstUserCSExport', formstr, 'post');
                MN = data.MN;
                index = layer.open({
                    type: 1,
                    area: ['900px', '150px'],
                    content: $("#DateTimeLayer") //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                });
                
            }

        });


        $("#BtnExport").on("click", function () {
            var TimeStart = $("#TimeStart").val();
            var TimeEnd = $("#TimeEnd").val();
            var formstr = "StartTime::" + TimeStart + "&TimeEnd::" + TimeEnd  + "&MN::" + MN;
            $.down('/Panel/Data2Excel', formstr, 'post');




        });

    });

    //回车键
    function getKey() {
        if (event.keyCode == 13) {
            SearchFunc();
        }
    }

    function SearchFunc() {
        var text = $("#SearchText").val();
        if (text == "") {
            table.reload("demo", {
                where: {
                    SortName: "DeviceId", Order: "Desc", Condition: " and IsDelete<>1"
                },
                page: {
                    curr: 1
                }
            });
        }
        else {
            table.reload("demo", {
                where: {
                    SortName: "DeviceId", Order: "Desc", Condition: " and IsDelete<>1 and Name like '%" + text + "%'"
                },
                page: {
                    curr: 1
                }
            });
        }
    }

</script>



